package com.compass.doctor.ui.chat.viewholder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.compass.doctor.R;
import com.compass.doctor.databinding.ChatMessagePostDiagnosisViewHolderBinding;
import com.compass.doctor.ui.chat.attachment.InquiryAttachment;
import com.compass.doctor.ui.chat.attachment.PostDiagnosisAttachment;
import com.compass.framework.utils.LogUtil;
import com.google.gson.Gson;
import com.netease.yunxin.kit.chatkit.ui.common.MessageHelper;
import com.netease.yunxin.kit.chatkit.ui.databinding.ChatBaseMessageViewHolderBinding;
import com.netease.yunxin.kit.chatkit.ui.fun.view.message.viewholder.FunChatBaseMessageViewHolder;
import com.netease.yunxin.kit.chatkit.ui.model.ChatMessageBean;
import com.netease.yunxin.kit.chatkit.ui.view.message.viewholder.ChatBaseMessageViewHolder;
import com.netease.yunxin.kit.common.utils.SizeUtils;

import java.util.Objects;

/**
 * Description：诊后建议ViewHolder
 * Date:2024/1/18 15:51
 */
public class PostDiagnosisViewHolder extends FunChatBaseMessageViewHolder {
    public static final String TAG = "InquiryViewHolder";
    ChatMessagePostDiagnosisViewHolderBinding binding;
    PostDiagnosisAttachment attachment;

    public PostDiagnosisViewHolder(@NonNull ChatBaseMessageViewHolderBinding parent, int viewType) {
        super(parent, viewType);
    }

    @Override
    protected void addViewToMessageContainer() {
        binding = ChatMessagePostDiagnosisViewHolderBinding.inflate(LayoutInflater.from(parent.getContext()), getMessageContainer(), true);

    }


    @Override
    public void bindData(ChatMessageBean message, ChatMessageBean lastMessage) {
        super.bindData(message, lastMessage);
        currentMessage = message;
        attachment = (PostDiagnosisAttachment) message.getMessageData().getMessage().getAttachment();
        if (attachment == null) {
            return;
        }

        LogUtil.INSTANCE.e(TAG+attachment.getContentValue());
        //设置ViewHolder展示UI的内容
        if (attachment.getContentValue().equals("null")) {
            //排除异常字符串为“null”的情况
            binding.tvContent.setText("暂无");
        }else {
            binding.tvContent.setText(attachment.getContentValue());
        }


    }



    @Override
    protected void onMessageBackgroundConfig(ChatMessageBean messageBean) {
        super.onMessageBackgroundConfig(messageBean);
        boolean isReceivedMsg = MessageHelper.isReceivedMessage(messageBean);
        View firstChild = baseViewBinding.messageContainer.getChildAt(0);
        if (isReceivedMsg) {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message);
        } else {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message_out);
        }
    }
}
